<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

/**
 * Class WechatQrcode
 *
 * @mixin \Eloquent
 */
class WechatQrcode extends Model
{
    protected $table = 'pw_wechat_qrcode';

	public $timestamps = false;

    protected $fillable = [
        'scene_name',
        'keyword',
        'typeid',
        'ticket',
        'createtime',
        'expiretime',
        'scan_times',
        'scan_fans',
        'qrcode_url',
        'qrcode_media_id'
    ];

    protected $guarded = [];

    public function fans(){
        return $this->hasMany(WechatFans::class, "event_key");
    }

    public function getTypeNameAttribute(){
        return $this->typeid==1 ? "永久" : "临时";
    }

    public function getCreateTimeAttribute($value)
    {
        return Carbon::createFromTimestamp($value)->toDateString();
    }

    public function getExpireTimeAttribute($value)
    {
        return $value == 0 ? "永久" : Carbon::createFromTimestamp($value)->toDateString();
    }


}